<?php
/**
 * Created by PhpStorm.
 * User: Woo
 * Date: 2018/3/7
 * Time: 14:29
 */

namespace App\Task;


use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class EasyChatTask extends Task
{
    private $fd;
    private $string;
    public function __construct($data)
    {
        $this->fd = $data['fd'];
        $this->string = $data['string'];
    }
    public function handle()
    {
        $fds = Redis::lrange('fds',0,-1);
        Log::info('receive', [$this->fd,$fds]);
        $fds = array_diff($fds,[$this->fd]);
        foreach($fds as $fd){
            app('swoole')->push($fd, $this->string);
        }
    }
    public function finish(){

    }
}